<template>
	<view>
		<view class="address">
			<!-- 按钮 -->
			<button  v-if="Object.keys(address).length === 0" @click="choose" type="primary" size="mini">请选中收货地址</button>
			<!-- 地址内容 -->
			<view class="content" v-else>
				<view class="top">
					<view class="name">
						收货人：{{address.userName}}
					</view>
					<view class="phone">
						<text>电话：{{address.telNumber}}</text>
						<uni-icons type="right"></uni-icons>
					</view>
				</view>
				<view class="bottom">
					收货地址：{{addstr}}
				</view>
			</view>
			<!-- 图片 -->
			<image class="border" src="/static/images/border.png"></image>
		</view>
	</view>
</template>

<script>
	import {mapMutations,mapState,mapGetters} from 'vuex'
	export default {
		name:"my-address",
		computed:{
			...mapState('m_user',['address']),
			...mapGetters('m_user',['addstr'])
		},
		methods:{
			...mapMutations('m_user',['updateAddress']),
			// 获取收货地址
			choose(){
				// 使用微信的收货地址
				uni.chooseAddress({
					success:res=>{
						this.updateAddress(res)
						
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.address {
		position: relative;
		height: 90px;

		button {
			position: absolute;
			left: 50%;
			top: 50%;
			transform: translate(-50%, -50%);
		}

		.border {
			width: 100%;
			height: 5px;
			position: absolute;
			left: 0;
			bottom: 0;
		}
		.content{
			box-sizing: border-box;
			padding: 10px 6px;
			height: 100%;
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			font-size: 12px;
			.top{
				display: flex;
				justify-content: space-between;
			}
		}
	}

</style>